function formatTime(date) {
  var year = date.getFullYear()
  var month = date.getMonth() + 1
  var day = date.getDate()

  var hour = date.getHours()
  var minute = date.getMinutes()
  var second = date.getSeconds()


  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
  n = n.toString()
  return n[1] ? n : '0' + n
}

module.exports = {
  formatTime: formatTime,
  phoneContentToElement: function(phone_content){
    var b1 = /<div class=\"editor_row\">(.*?)<\/div>/gi;
    var s1 = phone_content.match(b1);
    var detailElements = [];
    for (var i = 0; i < s1.length; i++) {

      // 查看是图片还是文字
      var b2 = /<img src=\"([^\"]*?)\">/gi;
      var s2 = s1[i].match(b2);
      // 大于0为图片
      if (s2 != null && s2.length > 0) {
        for (var j = 0; j < s2.length; j++) {
          var item = {};
          item.type = 'image';
          item.url = s2[j].replace(b2, "$1");
          detailElements.push(item);
        }
      } else {
        var item = {};
        item.type = 'word';
        item.text = s1[i].replace(b1, "$1");
        detailElements.push(item);
      }
      // img 的src
      // console.log(RegExp.$1)
    }
    return detailElements;
  },
  makeRandom: function(len){
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (var i = 0; i < len; i++) {
      pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
  }
}


